package com.lizardmind.haofudoctor.ui.aboutMe.set

import android.content.Intent
import android.os.Bundle
import android.view.View
import com.blankj.utilcode.util.EncodeUtils
import com.linxiao.framework.activity.BaseActivity
import com.linxiao.framework.dialog.AlertDialogBuilder
import com.linxiao.framework.dialog.AlertDialogManager
import com.linxiao.framework.permission.PermissionManager
import com.linxiao.framework.util.getDataBinding
import com.linxiao.framework.util.toasts
import com.lizardmind.haofudoctor.R
import com.lizardmind.haofudoctor.databinding.ActivitySetBinding
import com.lizardmind.haofudoctor.other.clearCacheFile
import com.lizardmind.haofudoctor.other.getCacheFileSize
import com.lizardmind.haofudoctor.other.logOut
import kotlinx.android.synthetic.main.activity_set.*
import kotlinx.android.synthetic.main.include_title_text.view.*
import org.jetbrains.anko.intentFor
import org.jetbrains.anko.sdk25.coroutines.onClick

/**
 * Created by Administrator on 2017/10/27.
 * 设置activity
 */
class SetActivity : BaseActivity(){

    val binding by lazy { getDataBinding<ActivitySetBinding>(R.layout.activity_set) }
    override fun onCreatRootView(): View {
       return binding.root
    }

    override fun onInitView(savedInstanceState: Bundle?) {
        titleSetAc.apply {
            titleText.text="设置"
            imgLeft.setImageResource(R.mipmap.back)
            imgLeft.onClick { finish() }
        }

        tvCacheNum.text = getCacheFileSize()

        tvChangePassword.setOnClickListener {
            startActivity(intentFor<ChangePasswordActivity>())
        }
        layoutClearCache.setOnClickListener{
            AlertDialogManager.createAlertDialogBuilder()
                    .setMessage("确定要清空缓存吗？")
                    .setPositiveText("确定")
                    .setPositiveButton { _, _ ->
                        clearCacheFile()
                        tvCacheNum.text = getCacheFileSize()
                    }
                    .setNegativeText("取消")
                    .setNegativeButton { _, _ ->  }
                    .setCancelable(true)
                    .show()
        }
        tvExit.onClick { logOut() }
    }
}